package com.hqj.controller;

import com.alibaba.fastjson.JSON;
import com.hqj.entity.Getuser;
import com.hqj.service.GetuserServiceI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 租方管理模块控制器
 */
@Controller
@RequestMapping("/guc")
public class GetUserController extends BaseController<Getuser>{
    @Resource(name="getuserServiceI") //按照名称注入
    private GetuserServiceI gsi;

    @Override
    public String index() {
        return "pages/user/index";
    }

    @Override
    public String addEdit(HttpServletRequest req, Model model) {
        String id = req.getParameter("id");
        if(id!=null){
            Getuser g = new Getuser();
            g.setId(Integer.parseInt(id));
            g = gsi.get(g);
            //把数据写出到跳转的页面
            model.addAttribute("gu",g);
            return "pages/user/edit";
        }
        return "pages/user/add";
    }

    @Override
    public String find(Getuser o) {
        List<Getuser> list = gsi.find(o);
        Map<String,Object> map = new HashMap<>();
        map.put("msg","");
        map.put("code","0");
        map.put("data",list);
        map.put("count",list.size());
        return JSON.toJSONString(map);
    }

    @Override
    public Map<String, Object> add(Getuser getuser) {
        return gsi.add(getuser);
    }

    @Override
    public Map<String, Object> edit(Getuser getuser) {
        return gsi.edit(getuser);
    }

    @Override
    public Map<String, Object> remove(Getuser getuser) {
        return gsi.remove(getuser.getId());
    }


}
